import os
from tqdm import tqdm


imgPath="G:\数据集\植保所\分类目标图片\外来入侵害虫\重新整理后纯英的版本"

classes = os.listdir(imgPath)

for className in classes:
    images = os.listdir(os.path.join(imgPath,className))
    index = 0
    for image in tqdm(images):

        os.rename(os.path.join(imgPath,className, image),
                  os.path.join(imgPath,className, className+"_"+str(index)+"."+image.split(".")[1]))
        index=index+1

# imgPath="G:\数据集\植保所\分类目标图片\斑潜蝇\归类后数据\按物种归类"
#
# classes = os.listdir(imgPath)
# index=0
# for className in classes:
#     images = os.listdir(os.path.join(imgPath,className))
#     nameEnglish=""
#     if className=="番茄斑潜蝇":
#         nameEnglish='fq'
#     if className=="美洲斑潜蝇":
#         nameEnglish='mz'
#     if className=="南美斑潜蝇":
#         nameEnglish='nm'
#     if className=="三叶斑潜蝇":
#         nameEnglish='sy'
#     if className=="葱斑潜蝇":
#         nameEnglish='c'
#     # 这是用来给图片名前加类别名的
#     for image in tqdm(images):
#
#         os.rename(os.path.join(imgPath,className, image),
#                   os.path.join(imgPath,className, nameEnglish+"_"+image))
